package guda.mrpc.core.client;

import guda.mrpc.core.client.proxy.CglibClientProxy;
import guda.mrpc.core.client.proxy.ClientProxy;
import guda.mrpc.core.config.ClientConfig;

/**
 * Created by well on 17/5/24.
 */
public class RpcClient {

    private ClientConfig clientConfig;

    private ClientProxy clientProxy=new CglibClientProxy();

    public RpcClient() {
    }


    public void stop() {
        ConnectionFactory.instance().shutdown();
    }


    public <T> T getProxyBean(Class<T> rpcInterface) {
        return (T) clientProxy.proxyInterface(new RpcInvoker(),rpcInterface);
    }



    public void bindReference(Class interfaceClass) {
        if (null != interfaceClass) {
            ReferenceConfig referenceConfig=new ReferenceConfig();
            referenceConfig.setInterfaceName(interfaceClass.getName());
            ReferenceFactory.instance().addHandler(interfaceClass.getName(), referenceConfig);
        }
    }

    public void bindReference(Class interfaceClass,String group,String version) {
        if (null != interfaceClass) {
            ReferenceConfig referenceConfig=new ReferenceConfig();
            referenceConfig.setInterfaceName(interfaceClass.getName());
            referenceConfig.setGroup(group);
            referenceConfig.setVersion(version);
            ReferenceFactory.instance().addHandler(interfaceClass.getName(), referenceConfig);
        }
    }

    public ClientConfig getClientConfig() {
        return clientConfig;
    }

    public void setClientConfig(ClientConfig clientConfig) {
        this.clientConfig = clientConfig;
    }

    public ClientProxy getClientProxy() {
        return clientProxy;
    }

    public void setClientProxy(ClientProxy clientProxy) {
        this.clientProxy = clientProxy;
    }
}
